package com.ww.basic.fun.closure

object Test4 {
  def main(args: Array[String]): Unit = {
    var messages = List("Hello", "World")
    // addMessage闭包捕获了messages变量，并且可以修改它
    val addMessage = (msg: String) => messages = messages :+ msg
    addMessage("Scala")
    println(messages) // List(Hello, World, Scala)
  }
}
